home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsdcolor.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  12.9 KB  |  344 lines

  1. /* Copyright (C) 1996, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsdcolor.h,v 1.3 2000/09/19 19:00:27 lpd Exp $ */
  20. /* Device color representation for drivers */
  21.  
  22. #ifndef gsdcolor_INCLUDED
  23. #  define gsdcolor_INCLUDED
  24.  
  25. #include "gsccolor.h"
  26. #include "gxarith.h"        /* for imod */
  27. #include "gxbitmap.h"
  28. #include "gxhttile.h"
  29. #include "gxcindex.h"
  30.  
  31. #ifndef gx_device_color_DEFINED
  32. #  define gx_device_color_DEFINED
  33. typedef struct gx_device_color_s gx_device_color;
  34. #endif
  35.  
  36. #ifndef gx_device_halftone_DEFINED
  37. #  define gx_device_halftone_DEFINED
  38. typedef struct gx_device_halftone_s gx_device_halftone;
  39. #endif
  40.  
  41. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  42.  * The definitions in the following section of the file are the only
  43.  * ones that should be used by read-only clients such as implementors
  44.  * of high-level driver functions.
  45.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  46.  
  47. /*
  48.  * A device color consists of a base color and an optional (tiled) mask.
  49.  * The base color may be a pure color, a binary halftone, or a colored
  50.  * bitmap (color halftone or colored Pattern).  The mask is used for
  51.  * both colored and uncolored Patterns.
  52.  */
  53.  
  54. /* Accessing a pure color. */
  55. #define gx_dc_is_pure(pdc)\
  56.   ((pdc)->type == gx_dc_type_pure)
  57. #define gx_dc_writes_pure(pdc, lop)\
  58.   (gx_dc_is_pure(pdc) && lop_no_S_is_T(lop))
  59. #define gx_dc_pure_color(pdc)\
  60.   ((pdc)->colors.pure)
  61.  
  62. /* Accessing the phase of a halftone. */
  63. #define gx_dc_phase(pdc)\
  64.   ((pdc)->phase)
  65.  
  66. /* Accessing a binary halftone. */
  67. #define gx_dc_is_binary_halftone(pdc)\
  68.   ((pdc)->type == gx_dc_type_ht_binary)
  69. #define gx_dc_binary_tile(pdc)\
  70.   (&(pdc)->colors.binary.b_tile->tiles)
  71. #define gx_dc_binary_color0(pdc)\
  72.   ((pdc)->colors.binary.color[0])
  73. #define gx_dc_binary_color1(pdc)\
  74.   ((pdc)->colors.binary.color[1])
  75.  
  76. /* Accessing a colored halftone. */
  77. #define gx_dc_is_colored_halftone(pdc)\
  78.   ((pdc)->type == gx_dc_type_ht_colored)
  79.  
  80. /* Test device colors for equality. */
  81. bool gx_device_color_equal(P2(const gx_device_color *pdevc1,
  82.                   const gx_device_color *pdevc2));
  83.  
  84. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  85.  * The definitions in the following section of the file, plus the ones
  86.  * just above, are the only ones that should be used by clients that
  87.  * set as well as read device colors.
  88.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  89.  
  90. #define color_is_set(pdc)\
  91.   ((pdc)->type != gx_dc_type_none)
  92. #define color_unset(pdc)\
  93.   ((pdc)->type = gx_dc_type_none)
  94.  
  95. #define gx_dc_is_null(pdc)\
  96.   ((pdc)->type == gx_dc_type_null)
  97. #define color_is_null(pdc) gx_dc_is_null(pdc)
  98. #define color_set_null(pdc)\
  99.   ((pdc)->type = gx_dc_type_null)
  100.  
  101. #define color_is_pure(pdc) gx_dc_is_pure(pdc)
  102. #define color_writes_pure(pdc, lop) gx_dc_writes_pure(pdc, lop)
  103. #define color_set_pure(pdc, color)\
  104.   ((pdc)->colors.pure = (color),\
  105.    (pdc)->type = gx_dc_type_pure)
  106.  
  107. /* Set the phase to an offset from the tile origin. */
  108. #define color_set_phase(pdc, px, py)\
  109.   ((pdc)->phase.x = (px),\
  110.    (pdc)->phase.y = (py))
  111. /* Set the phase from the halftone phase in a graphics state. */
  112. #define color_set_phase_mod(pdc, px, py, tw, th)\
  113.   color_set_phase(pdc, imod(-(px), tw), imod(-(py), th))
  114.  
  115. #define color_is_binary_halftone(pdc) gx_dc_is_binary_halftone(pdc)
  116. #define color_set_binary_halftone_component(pdc, ht, index, color0, color1, level)\
  117.   ((pdc)->colors.binary.b_ht = (ht),\
  118.    (pdc)->colors.binary.b_index = (index),\
  119.    (pdc)->colors.binary.color[0] = (color0),\
  120.    (pdc)->colors.binary.color[1] = (color1),\
  121.    (pdc)->colors.binary.b_level = (level),\
  122.    (pdc)->type = gx_dc_type_ht_binary)
  123. #define color_set_binary_halftone(pdc, ht, color0, color1, level)\
  124.   color_set_binary_halftone_component(pdc, ht, -1, color0, color1, level)
  125. #define color_set_binary_tile(pdc, color0, color1, tile)\
  126.   ((pdc)->colors.binary.b_ht = 0,\
  127.    (pdc)->colors.binary.color[0] = (color0),\
  128.    (pdc)->colors.binary.color[1] = (color1),\
  129.    (pdc)->colors.binary.b_index = -1, /* irrelevant */\
  130.    (pdc)->colors.binary.b_tile = (tile),\
  131.    (pdc)->type = gx_dc_type_ht_binary)
  132.  
  133. #define color_is_colored_halftone(pdc) gx_dc_is_colored_halftone(pdc)
  134. #define _color_set_c(pdc, i, b, l)\
  135.   ((pdc)->colors.colored.c_base[i] = (b),\
  136.    (pdc)->colors.colored.c_level[i] = (l))
  137. void gx_complete_rgb_halftone(P2(gx_device_color *pdevc,
  138.                  gx_device_halftone *pdht));
  139. #define color_set_rgb_halftone(pdc, ht, br, lr, bg, lg, bb, lb, a)\
  140.   (_color_set_c(pdc, 0, br, lr),\
  141.    _color_set_c(pdc, 1, bg, lg),\
  142.    _color_set_c(pdc, 2, bb, lb),\
  143.    (pdc)->colors.colored.alpha = (a),\
  144.    gx_complete_rgb_halftone(pdc, ht))
  145. /* Some special clients set the individual components separately. */
  146. void gx_complete_cmyk_halftone(P2(gx_device_color *pdevc,
  147.                   gx_device_halftone *pdht));
  148. #define color_finish_set_cmyk_halftone(pdc, ht)\
  149.   gx_complete_cmyk_halftone(pdc, ht)
  150. #define color_set_cmyk_halftone(pdc, ht, bc, lc, bm, lm, by, ly, bk, lk)\
  151.    (_color_set_c(pdc, 0, bc, lc),\
  152.     _color_set_c(pdc, 1, bm, lm),\
  153.     _color_set_c(pdc, 2, by, ly),\
  154.     _color_set_c(pdc, 3, bk, lk),\
  155.     color_finish_set_cmyk_halftone(pdc, ht))
  156.  
  157. /* Note that color_set_null_pattern doesn't set mask.ccolor. */
  158. #define color_set_null_pattern(pdc)\
  159.  ((pdc)->mask.id = gx_no_bitmap_id,\
  160.   (pdc)->mask.m_tile = 0,\
  161.   (pdc)->colors.pattern.p_tile = 0,\
  162.   (pdc)->type = gx_dc_type_pattern)
  163.  
  164. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  165.  * The remaining definitions are internal ones that are included in this
  166.  * file only because C's abstraction mechanisms aren't strong enough to
  167.  * allow us to keep them separate and still have in-line access to the
  168.  * commonly used members.
  169.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  170.  
  171. /* Define opaque types for objects referenced by device colors. */
  172.  
  173. #ifndef gx_ht_tile_DEFINED
  174. #  define gx_ht_tile_DEFINED
  175. typedef struct gx_ht_tile_s gx_ht_tile;
  176. #endif
  177.  
  178. #ifndef gx_color_tile_DEFINED
  179. #  define gx_color_tile_DEFINED
  180. typedef struct gx_color_tile_s gx_color_tile;
  181. #endif
  182.  
  183. /*
  184.  * The device color in the graphics state is computed from client color
  185.  * specifications, and kept current through changes in transfer function,
  186.  * device, and (if relevant) halftone phase.
  187.  * (gx_set_dev_color sets the device color if needed.)
  188.  * For binary halftones (and eventually colored halftones as well),
  189.  * the bitmaps are only cached, so internal clients (the painting operators)
  190.  * must call gx_color_load to ensure that the bitmap is available.
  191.  * Device color elements set by gx_color_load are marked with @ below.
  192.  *
  193.  * Base colors are represented as follows:
  194.  *
  195.  *      Pure color (gx_dc_pure):
  196.  *              colors.pure = the color;
  197.  *      Binary halftone (gx_dc_ht_binary):
  198.  *              colors.binary.b_ht = the device halftone;
  199.  *        colors.binary.b_index = -1 if b_ht is the halftone,
  200.  *          otherwise an index in b_ht.components
  201.  *              colors.binary.color[0] = the color for 0s (darker);
  202.  *              colors.binary.color[1] = the color for 1s (lighter);
  203.  *              colors.binary.b_level = the number of pixels to lighten,
  204.  *                0 < halftone_level < P, the number of pixels in the tile;
  205.  *      @       colors.binary.b_tile points to an entry in the binary
  206.  *                tile cache.
  207.  *      Colored halftone (gx_dc_ht_colored):
  208.  *              colors.colored.c_ht = the device halftone;
  209.  *              colors.colored.c_level[0..N-1] = the halftone levels,
  210.  *                like b_level;
  211.  *              colors.colored.c_base[0..N-1] = the base colors;
  212.  *                N = the device color_info.num_components
  213.  *            (3 for RGB devices, 4 for CMYK devices, ? for DeviceN);
  214.  *                0 <= c_level[i] < P;
  215.  *                0 <= c_base[i] <= dither_rgb;
  216.  *              colors.colored.alpha = the opacity.
  217.  *        colors.colored.plane_mask: bit 2^i = 1 iff c_level[i] != 0
  218.  *      Colored PatternType 1 pattern (gx_dc_pattern):
  219.  *              (mask is also set, see below)
  220.  *      @       colors.pattern.p_tile points to a gx_color_tile in
  221.  *                the pattern cache, or is NULL for a null pattern.
  222.  *
  223.  * The phase element is used for all colors except pure ones.  It holds the
  224.  * negative of the graphics state halftone phase, modulo the halftone tile
  225.  * size.
  226.  *
  227.  * The ccolor element is used for all kinds of patterns.  It is needed for
  228.  * rendering the pattern.
  229.  *
  230.  * The mask elements of a device color are only used for PatternType 1
  231.  * patterns:
  232.  *      Non-pattern:
  233.  *              mask is unused.
  234.  *      Pattern:
  235.  *              mask.id gives the ID of the pattern (and its mask);
  236.  *              mask.m_phase holds the negative of the graphics state
  237.  *                halftone phase;
  238.  *      @       mask.m_tile points to a gx_color_tile in the pattern cache,
  239.  *                or is NULL for a pattern that doesn't require a mask.
  240.  *                (The 'bits' of the tile are not accessed.)
  241.  *                For colored patterns requiring a mask, p_tile and
  242.  *                mask.m_tile point to the same cache entry.
  243.  * For masked colors, gx_set_dev_color replaces the type with a different
  244.  * type that applies the mask when painting.  These types are not defined
  245.  * here, because they are only used in Level 2.
  246.  */
  247.  
  248. /* Define the (opaque) type for device color types. */
  249. /* The name is an unfortunate anachronism. */
  250. typedef struct gx_device_color_type_s gx_device_color_type_t;
  251. typedef const gx_device_color_type_t *gx_device_color_type;
  252.  
  253. struct gx_device_color_s {
  254.     /*
  255.      * Since some compilers don't allow static initialization of a
  256.      * union, we put the type first.
  257.      */
  258.     gx_device_color_type type;
  259.     /*
  260.      * See the comment above for descriptions of the members.  We use
  261.      * b_, c_, and p_ member names because some old compilers don't
  262.      * allow the same name to be used for two different structure
  263.      * members even when it's unambiguous.
  264.      */
  265.     union _c {
  266.     gx_color_index pure;
  267.     struct _bin {
  268.         const gx_device_halftone *b_ht;
  269.         gx_color_index color[2];
  270.         uint b_level;
  271.         int b_index;
  272.         gx_ht_tile *b_tile;
  273.     } binary;
  274.     struct _col {
  275.         gx_device_halftone *c_ht; /* non-const for setting cache ptr */
  276.         byte c_base[GX_DEVICE_COLOR_MAX_COMPONENTS];
  277.         uint c_level[GX_DEVICE_COLOR_MAX_COMPONENTS];
  278.         ushort /*gx_color_value */ alpha;
  279. #if GX_DEVICE_COLOR_MAX_COMPONENTS <= ARCH_SIZEOF_SHORT * 8
  280.         ushort plane_mask;
  281. #else
  282. #if GX_DEVICE_COLOR_MAX_COMPONENTS <= ARCH_SIZEOF_INT * 8
  283.         uint plane_mask;
  284. #else
  285.         gx_color_index plane_mask;
  286. #endif
  287. #endif
  288.     } colored;
  289.     struct _pat {
  290.         gx_color_tile *p_tile;
  291.     } /*(colored) */ pattern;
  292.     } colors;
  293.     gs_int_point phase;
  294.     gs_client_color ccolor;    /* needed for remapping patterns, */
  295.                 /* not set for non-pattern colors */
  296.     struct _mask {
  297.     struct mp_ {
  298.         short x, y;
  299.     } m_phase;
  300.     gx_bitmap_id id;
  301.     gx_color_tile *m_tile;
  302.     } mask;
  303. };
  304.  
  305. /*extern_st(st_device_color); *//* in gxdcolor.h */
  306. #define public_st_device_color() /* in gxcmap.c */\
  307.   gs_public_st_composite(st_device_color, gx_device_color, "gx_device_color",\
  308.     device_color_enum_ptrs, device_color_reloc_ptrs)
  309. #define st_device_color_max_ptrs (st_client_color_max_ptrs + 2)
  310.  
  311. /*
  312.  * Define the standard device color types.
  313.  * We define them here as pointers to the real types only because a few
  314.  * C compilers don't allow declaring externs with abstract struct types;
  315.  * we redefine them as macros in gxdcolor.h where the concrete type for
  316.  * gx_device_color_procs is available.
  317.  * We spell out the definition of gx_device_color type because some
  318.  * C compilers can't handle the typedef correctly.
  319.  */
  320. #ifndef gx_dc_type_none
  321. extern const gx_device_color_type_t *const gx_dc_type_none;    /* gxdcolor.c */
  322. #endif
  323. #ifndef gx_dc_type_null
  324. extern const gx_device_color_type_t *const gx_dc_type_null;    /* gxdcolor.c */
  325. #endif
  326. #ifndef gx_dc_type_pure
  327. extern const gx_device_color_type_t *const gx_dc_type_pure;    /* gxdcolor.c */
  328. #endif
  329.         /*
  330.          * We don't declare gx_dc_pattern here, so as not to create
  331.          * a spurious external reference in Level 1 systems.
  332.          */
  333. #ifndef gx_dc_type_pattern
  334.                                     /*extern const gx_device_color_type_t * const gx_dc_type_pattern; *//* gspcolor.c */
  335. #endif
  336. #ifndef gx_dc_type_ht_binary
  337. extern const gx_device_color_type_t *const gx_dc_type_ht_binary;    /* gxht.c */
  338. #endif
  339. #ifndef gx_dc_type_ht_colored
  340. extern const gx_device_color_type_t *const gx_dc_type_ht_colored;    /* gxcht.c */
  341. #endif
  342.  
  343. #endif /* gsdcolor_INCLUDED */
  344.